# This assumes that the procdef.sql script has been run
import common
import DCOracle2
import unittest

class test_bindingarrays(common.TestCase):
    
    def test_function(self):

        self.assertEqual(
            self.c.execute('begin emp_actions.testi(:1, 5); end;', "Mavra Chang"),
            8
            )
        
    def test_BindingArray(self):
        
        bao1 = self.db.BindingArray(1, 32, 1)
        bao1[0] = DCOracle2.TypeCoercion("Fred Flintstone",1)
    
        self.assertEqual(
            self.c.execute("begin emp_actions.testi(:1, 4); end;", bao1),
            8
            )
        
        self.assertEqual(bao1[0],'Fred Flintstone')

    def test_2BindingArrays(self):

        bao1 = self.db.BindingArray(1,32,5)
        bao2 = self.db.BindingArray(1,32,5)
        bao2[0] = "manager"

        self.assertEqual(
            self.c.execute("begin emp_actions.findy(7902, :1, :2); end;", bao1, bao2),
            8
            )
        
        self.assertEqual(bao1[0],'FORD')
        self.assertEqual(bao2[0],'ANALYST')

    def test_manyBindingArrays(self):

        bao = self.db.BindingArray(10,20,'SQLT_STR')
        bao[0] = 'Mary'
        bao[1] = 'Had'
        bao[2] = 'A'
        bao[3] = 'Little'
        bao[4] = 'Lamb'

        c = self.c

        self.assertEqual(
            c.execute("begin emp_actions.taketab(:1); end;", bao),
            8
            )

        self.assertEqual(
            c.procedures.emp_actions.taketab(bao),
            []
            )

        self.assertEqual(
            c.procedures.emp_actions.taketab(['Mary','had','a','little','lamb']),
            []
            )

        self.assertEqual(
            c.procedures.emp_actions.returntab(),
            ['Mary', 'had', 'a', 'little', 'lamb']
            )

    def test_tab(self):

        c = self.c

        tabin = c.procedure.emp_actions.taketab

        invars = self.db.BindingArray(20, 20, 'SQLT_STR')

        invars[0] = '123'
        invars[1] = '456'

        self.assertEqual(tabin(invars),[])
        
if __name__ == '__main__':
    unittest.main()
        
